/*
 * UI.java
 *
 * Created on 21 april 2008, 15:00
 */
package ui;

import controller.Controller;
import entities.CD;
import entities.Persoon;
import entities.Uitlening;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author  BosCH
 */
public class UI extends javax.swing.JFrame {

  private Controller con;

  /** Creates new form UI */
  public UI() {
    initComponents();
    con = Controller.restore();
    if (con == null) {
      con = new Controller();
    }
    con.setUI(this);
    this.vulPersonen();
    this.vulCDS();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jlPersonen = new javax.swing.JList();
        jbNieuwPersoon = new javax.swing.JButton();
        jpNieuwPersoon = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfNaamPersoon = new javax.swing.JTextField();
        jbSavePersoon = new javax.swing.JButton();
        jbCancelPersoon = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlCDs = new javax.swing.JList();
        jbNieuwCD = new javax.swing.JButton();
        jpNieuweCD = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jtfArtiest = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfTitel = new javax.swing.JTextField();
        jbSaveCD = new javax.swing.JButton();
        jbCancelCD = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jlUitleningen = new javax.swing.JList();
        jbVerwijderUitlening = new javax.swing.JButton();
        jbNieuweUitlening = new javax.swing.JButton();
        jpNieuweUitlening = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jtfDatum = new javax.swing.JTextField();
        jbSaveUitlening = new javax.swing.JButton();
        jbCancelUitlening = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jbToonUitleningen = new javax.swing.JButton();
        jbToonUitlening = new javax.swing.JButton();
        jbSaveAll = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlPersonen.setBorder(javax.swing.BorderFactory.createTitledBorder("Personen"));
        jlPersonen.setModel(new DefaultListModel());
        jlPersonen.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlPersonenValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jlPersonen);

        jbNieuwPersoon.setText("nieuw persoon");
        jbNieuwPersoon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNieuwPersoonActionPerformed(evt);
            }
        });

        jpNieuwPersoon.setVisible(false);

        jLabel1.setText("naam");

        jbSavePersoon.setText("save");
        jbSavePersoon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSavePersoonActionPerformed(evt);
            }
        });

        jbCancelPersoon.setText("cancel");
        jbCancelPersoon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelPersoonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpNieuwPersoonLayout = new javax.swing.GroupLayout(jpNieuwPersoon);
        jpNieuwPersoon.setLayout(jpNieuwPersoonLayout);
        jpNieuwPersoonLayout.setHorizontalGroup(
            jpNieuwPersoonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNieuwPersoonLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpNieuwPersoonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jpNieuwPersoonLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jtfNaamPersoon, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpNieuwPersoonLayout.createSequentialGroup()
                        .addComponent(jbSavePersoon, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbCancelPersoon)))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        jpNieuwPersoonLayout.setVerticalGroup(
            jpNieuwPersoonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNieuwPersoonLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpNieuwPersoonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfNaamPersoon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jpNieuwPersoonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbSavePersoon)
                    .addComponent(jbCancelPersoon))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jlCDs.setBorder(javax.swing.BorderFactory.createTitledBorder("CD's"));
        jlCDs.setModel(new DefaultListModel());
        jlCDs.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jlCDsValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jlCDs);

        jbNieuwCD.setText("nieuwe CD");
        jbNieuwCD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNieuwCDActionPerformed(evt);
            }
        });

        jpNieuweCD.setVisible(false);

        jLabel2.setText("artiest");

        jLabel3.setText("titel");

        jbSaveCD.setText("save");
        jbSaveCD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSaveCDActionPerformed(evt);
            }
        });

        jbCancelCD.setText("cancel");
        jbCancelCD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelCDActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpNieuweCDLayout = new javax.swing.GroupLayout(jpNieuweCD);
        jpNieuweCD.setLayout(jpNieuweCDLayout);
        jpNieuweCDLayout.setHorizontalGroup(
            jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNieuweCDLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpNieuweCDLayout.createSequentialGroup()
                        .addGroup(jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfTitel, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                            .addComponent(jtfArtiest, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(jpNieuweCDLayout.createSequentialGroup()
                        .addComponent(jbSaveCD)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
                        .addComponent(jbCancelCD)
                        .addGap(21, 21, 21))))
        );
        jpNieuweCDLayout.setVerticalGroup(
            jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNieuweCDLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfArtiest, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtfTitel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpNieuweCDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbSaveCD)
                    .addComponent(jbCancelCD))
                .addContainerGap(33, Short.MAX_VALUE))
        );

        jlUitleningen.setBorder(javax.swing.BorderFactory.createTitledBorder("Uitleningen"));
        jlUitleningen.setModel(new DefaultListModel());
        jScrollPane3.setViewportView(jlUitleningen);

        jbVerwijderUitlening.setText("verwijder uitlening");
        jbVerwijderUitlening.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbVerwijderUitleningActionPerformed(evt);
            }
        });

        jbNieuweUitlening.setText("maak uitlening");
        jbNieuweUitlening.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNieuweUitleningActionPerformed(evt);
            }
        });

        jpNieuweUitlening.setVisible(false);

        jLabel4.setText("datum");

        jbSaveUitlening.setText("save");
        jbSaveUitlening.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSaveUitleningActionPerformed(evt);
            }
        });

        jbCancelUitlening.setText("cancel");
        jbCancelUitlening.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelUitleningActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpNieuweUitleningLayout = new javax.swing.GroupLayout(jpNieuweUitlening);
        jpNieuweUitlening.setLayout(jpNieuweUitleningLayout);
        jpNieuweUitleningLayout.setHorizontalGroup(
            jpNieuweUitleningLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNieuweUitleningLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpNieuweUitleningLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpNieuweUitleningLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(40, 40, 40)
                        .addComponent(jtfDatum, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(58, Short.MAX_VALUE))
                    .addGroup(jpNieuweUitleningLayout.createSequentialGroup()
                        .addComponent(jbSaveUitlening)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                        .addComponent(jbCancelUitlening)
                        .addGap(36, 36, 36))))
        );
        jpNieuweUitleningLayout.setVerticalGroup(
            jpNieuweUitleningLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNieuweUitleningLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpNieuweUitleningLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtfDatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addGroup(jpNieuweUitleningLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbSaveUitlening)
                    .addComponent(jbCancelUitlening))
                .addGap(26, 26, 26))
        );

        jLabel5.setText("x");

        jLabel6.setText("x");

        jbToonUitleningen.setText("toon uitleningen");
        jbToonUitleningen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbToonUitleningenActionPerformed(evt);
            }
        });

        jbToonUitlening.setText("toon uitlening");
        jbToonUitlening.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbToonUitleningActionPerformed(evt);
            }
        });

        jbSaveAll.setText("save all");
        jbSaveAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSaveAllActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 734, Short.MAX_VALUE)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                            .addComponent(jbToonUitleningen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbNieuwPersoon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jpNieuwPersoon, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbSaveAll, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                            .addComponent(jpNieuweUitlening, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbNieuweUitlening, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbVerwijderUitlening, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jpNieuweCD, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbNieuwCD, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbToonUitlening, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbToonUitleningen)
                            .addComponent(jbVerwijderUitlening)
                            .addComponent(jbToonUitlening))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbNieuwPersoon)
                            .addComponent(jbNieuweUitlening)
                            .addComponent(jbNieuwCD))
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE))
                        .addGap(114, 114, 114)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jpNieuwPersoon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(84, 84, 84)
                                .addComponent(jbSaveAll)
                                .addGap(109, 109, 109)
                                .addComponent(jLabel5))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jpNieuweUitlening, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE)
                                .addComponent(jLabel6)))
                        .addGap(40, 40, 40))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jpNieuweCD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void jbNieuwPersoonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNieuwPersoonActionPerformed
      jpNieuwPersoon.setVisible(true);
    }//GEN-LAST:event_jbNieuwPersoonActionPerformed

    private void jbCancelPersoonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelPersoonActionPerformed
      jpNieuwPersoon.setVisible(false);
    }//GEN-LAST:event_jbCancelPersoonActionPerformed

    private void jbNieuweUitleningActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNieuweUitleningActionPerformed
      jpNieuweUitlening.setVisible(true);
    }//GEN-LAST:event_jbNieuweUitleningActionPerformed

    private void jbCancelUitleningActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelUitleningActionPerformed
      jpNieuweUitlening.setVisible(false);
    }//GEN-LAST:event_jbCancelUitleningActionPerformed

    private void jbNieuwCDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNieuwCDActionPerformed
      jpNieuweCD.setVisible(true);
    }//GEN-LAST:event_jbNieuwCDActionPerformed

    private void jbCancelCDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelCDActionPerformed
      jpNieuweCD.setVisible(false);
    }//GEN-LAST:event_jbCancelCDActionPerformed

    private void jbSavePersoonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSavePersoonActionPerformed
      String naam = jtfNaamPersoon.getText();
      con.maakPersoon(naam);
      vulPersonen();
      jpNieuwPersoon.setVisible(false);
    }//GEN-LAST:event_jbSavePersoonActionPerformed

    private void jbSaveCDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSaveCDActionPerformed
      String artiest = jtfArtiest.getText();
      String titel = jtfTitel.getText();
      con.maakCD(artiest, titel);
      vulCDS();
      jpNieuweCD.setVisible(false);
    }//GEN-LAST:event_jbSaveCDActionPerformed

    private void jbSaveUitleningActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSaveUitleningActionPerformed
      String datum = jtfDatum.getText();
      Persoon p = (Persoon) jlPersonen.getSelectedValue();
      CD cd = (CD) jlCDs.getSelectedValue();
      con.maakUitlening(p, cd, datum);
      vulUitleningenVanPersoon(p);
      jpNieuweUitlening.setVisible(false);
    }//GEN-LAST:event_jbSaveUitleningActionPerformed

    private void jbToonUitleningenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbToonUitleningenActionPerformed

      Persoon p = (Persoon) jlPersonen.getSelectedValue();
      vulUitleningenVanPersoon(p);

    }//GEN-LAST:event_jbToonUitleningenActionPerformed

    private void jlPersonenValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlPersonenValueChanged
      clearUitleningenLijst();
    }//GEN-LAST:event_jlPersonenValueChanged

    private void jlCDsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlCDsValueChanged
      clearUitleningenLijst();
    }//GEN-LAST:event_jlCDsValueChanged

    private void jbToonUitleningActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbToonUitleningActionPerformed
      CD cd = (CD) jlCDs.getSelectedValue();
      vulUitleningVanCD(cd);
    }//GEN-LAST:event_jbToonUitleningActionPerformed

    private void jbVerwijderUitleningActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbVerwijderUitleningActionPerformed
      Uitlening uit = (Uitlening) jlUitleningen.getSelectedValue();
      con.verwijderUitlening(uit);
      vulUitleningenVanPersoon(uit.getPersoon());
    }//GEN-LAST:event_jbVerwijderUitleningActionPerformed

    private void jbSaveAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSaveAllActionPerformed
      con.saveAll();
      JOptionPane.showMessageDialog(null, "de gegevens zijn opgeslagen");
    }//GEN-LAST:event_jbSaveAllActionPerformed

  public void vulPersonen() {
    List<Persoon> personen = con.getPersonen();
    DefaultListModel lm = (DefaultListModel) jlPersonen.getModel();
    lm.clear();
    for (Persoon p : personen) {
      lm.addElement(p);
    }
    //ook wel handig:
    jlPersonen.setModel(lm);
    //Anders zie je m niet
  }

  public void vulCDS() {
    List<CD> cds = con.getCDs();
    DefaultListModel lm = (DefaultListModel) jlCDs.getModel();
    lm.clear();
    for (CD cd : cds) {
      lm.addElement(cd);
    }
    //niet vergeten he:
    jlCDs.setModel(lm);
  }

  public void vulUitleningenVanPersoon(Persoon p) {
    List<Uitlening> uits = con.getUitleningenVanPersoon(p);
    DefaultListModel lm = (DefaultListModel) jlUitleningen.getModel();
    lm.clear();
    for (Uitlening uit : uits) {
      lm.addElement(uit);
    }
  }

  public void vulUitleningVanCD(CD cd) {
    Uitlening uit = con.getUitleningVanCD(cd);
    DefaultListModel lm = (DefaultListModel) jlUitleningen.getModel();
    lm.clear();
    lm.addElement(uit);
  }

  public void clearUitleningenLijst() {
    DefaultListModel lm = (DefaultListModel) jlUitleningen.getModel();
    lm.clear();
  }

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

      public void run() {
        new UI().setVisible(true);
      }
    });
  }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jbCancelCD;
    private javax.swing.JButton jbCancelPersoon;
    private javax.swing.JButton jbCancelUitlening;
    private javax.swing.JButton jbNieuwCD;
    private javax.swing.JButton jbNieuwPersoon;
    private javax.swing.JButton jbNieuweUitlening;
    private javax.swing.JButton jbSaveAll;
    private javax.swing.JButton jbSaveCD;
    private javax.swing.JButton jbSavePersoon;
    private javax.swing.JButton jbSaveUitlening;
    private javax.swing.JButton jbToonUitlening;
    private javax.swing.JButton jbToonUitleningen;
    private javax.swing.JButton jbVerwijderUitlening;
    private javax.swing.JList jlCDs;
    private javax.swing.JList jlPersonen;
    private javax.swing.JList jlUitleningen;
    private javax.swing.JPanel jpNieuwPersoon;
    private javax.swing.JPanel jpNieuweCD;
    private javax.swing.JPanel jpNieuweUitlening;
    private javax.swing.JTextField jtfArtiest;
    private javax.swing.JTextField jtfDatum;
    private javax.swing.JTextField jtfNaamPersoon;
    private javax.swing.JTextField jtfTitel;
    // End of variables declaration//GEN-END:variables
}
